package erlwitch;

public abstract class Butler implements Runnable {

	private int times;
	private int maxTimes;
	
	public Butler(int maxTimes) {
		this.maxTimes = maxTimes;
	}
	
	public synchronized void setMaxTimes(int maxTimes) {
		this.maxTimes = maxTimes;
	}
	
	public synchronized void reset() {
		times = 0;
	}
	
	public void run() {
		reset();
		while (true) {
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
			}
			times++;
			if (times >= maxTimes) {
				process();
				reset();
			}
		}
	}

	public abstract void process();
	
}
